<template>
  <div class="login-container">
    <el-card class="login-card" shadow="hover">
      <h3 slot="header" class="login-title">员工登录</h3>
      <el-form
        ref="staff"
        :model="staff"
        :rules="loginRules"
        label-width="80px"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            v-model="staff.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="staff.password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="margin-left: 65px" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
  
<script>
import { staffApi } from "@/api/api";
import { stopp } from "@/js/flower";

export default {
  data() {
    return {
      staff: {
        username: "",
        password: "",
      },
      loginRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    login() {
      this.$refs.staff.validate((valid) => {
        if (valid) {
          const staff = this.staff;
          staffApi.login(staff).then((resp) => {
            if (resp.data.code) {
              this.$router.push({
                path: "/admin",
              });
            } else {
              this.$message.error(resp.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
  },
  mounted() {
    localStorage.removeItem("selectedMenu");
    localStorage.removeItem("currentTab");
    stopp();
  },
};
</script>
  
  <style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login-card {
  position: relative;
  z-index: 1; /* 设置一个较大的 z-index 值，使登录框位于背景图之上 */
  width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
}

</style>
  